package com.jsl;

import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.general.BaseBean;

/**
 * @Description weaver数据处理工具类
 * @Author xw
 * @Date 2021/12/23
 */
public class NCCUtil {

    public static BaseBean baseBean = new BaseBean();
    /**
     * 获得表单table
     * @param workflowid 流程id
     * @return
     */
    public static String getFormtable(String workflowid) {
        String formtable="";
        String sql="select tablename from workflow_base t1,workflow_bill t2 where t1.id="+workflowid+" and t2.id=t1.formid";
        RecordSet recordSet=new RecordSet();
        recordSet.execute(sql);
        if(recordSet.next())
            formtable=recordSet.getString("tablename");
        return formtable;
    }

    /**
     * 获取ncc人员编码
     */
    public static String getItemValue(String table,String valueField,
                                      String field, String fieldValue) {

        RecordSet recordSet = new RecordSet();
        String sql = "select "+valueField+" from "+table+" where "+field+"='"+fieldValue+"'";
        baseBean.writeLog("[NCCUtil.getItemValue sql:]" + sql);
        recordSet.execute(sql);
        String itemValue = "";
        if (recordSet.next()) {
            itemValue = recordSet.getString(valueField);
        }
        return itemValue;
    }

    /**
     * 获取供应商主键
     * @param code 供应商编码
     * @return
     */
    public static String getPkSupplier(String code) {
        RecordSetDataSource recordSetDataSource = new RecordSetDataSource("NCC");
        String sql = "select PK_SUPPLIER from SUPPLIER where code='" + code + "'";
        baseBean.writeLog("[NCCUtil.getPkSupplier sql:]" + sql);
        try{
            recordSetDataSource.execute(sql);
            String pkSupplier = "";
            if (recordSetDataSource.next()) {
                pkSupplier = recordSetDataSource.getString("PK_SUPPLIER");
            }
            return pkSupplier;
        }catch (Exception e){
            return "";
        }


    }

    /**
     * 获取组织主键
     * @param code 组织编码
     * @return
     */
    public static String getPkOrganization(String code) {
        RecordSetDataSource recordSetDataSource = new RecordSetDataSource("NCC");
        String sql = "select PK_FINANCEORG from FINANCEORG_VIEW where code='" + code + "'";
        baseBean.writeLog("[NCCUtil.getPkOrganization sql:]" + sql);
        recordSetDataSource.execute(sql);
        String pkOrganization = "";
        if (recordSetDataSource.next()) {
            pkOrganization = recordSetDataSource.getString("PK_FINANCEORG");
        }

        return pkOrganization;
    }

    // CTPUTYPE_VIEW
    /**
     * 获取合同类型编号
     * @param key 合同类型主键
     * @return
     */
    public static String getPkContractType(String key) {
        RecordSetDataSource recordSetDataSource = new RecordSetDataSource("NCC");
        String sql = "select CODE from CTPUTYPE_VIEW where PK_BILLTYPEID='" + key + "'";
        baseBean.writeLog("[NCCUtil.getPkContractType sql:]" + sql);
        recordSetDataSource.execute(sql);
        String code = "";
        if (recordSetDataSource.next()) {
            code = recordSetDataSource.getString("CODE");
        }

        return code;
    }
}
